package it.infodea.tapestrydea.pages.demodea;

import it.infodea.tapestrydea.entities.demo.DogBean;
import it.infodea.tapestrydea.entities.demo.UserBean;
import it.infodea.tapestrydea.services.breadcrumb.BreadcrumbService;
import it.infodea.tapestrydea.support.annotations.PageInfo;
import it.infodea.tapestrydea.support.enumerations.SecurityGroup;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

@PageInfo(category = "demo", allowedSecurityGroup=SecurityGroup.ANONYMOUS, mode = PageInfo.MODE_NORMAL)
public class BEDDemoDea {

	@Inject
	private ComponentResources resources;

	@Inject
	private BreadcrumbService breadcrumbService;

	@Persist
	@Property
	private UserBean user;

	@Persist
	@Property
	private DogBean dog;

	@SuppressWarnings("unused")
	@Persist
	@Property
	private boolean dogVisible;

	@SetupRender
	void setup() {
		breadcrumbService.addBreadcrumb(resources);
		initUser();
		initDog();
	}

	private void initUser() {
		if (user == null) {
			user = UserBean.newInstance("Roberto", "Infodea", 31, 1L);
		}
	}

	private void initDog() {
		if (dog == null) {
			dog = DogBean.newInstance("Bobby", 5, 1L);
			dogVisible = true;
		}
	}

}
